package com.demo.controller;

import com.demo.pojo.Account;
import com.demo.service.AccountService;
import com.demo.service.impl.AccountServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.crypto.spec.PSource;
import java.util.List;

/**
 * @ClassName AccountController
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/4 20:16
 * @Version 1.0
 **/
@Controller
@RequestMapping("account")
public class AccountController {

    @Autowired
    AccountService accountService;

    @GetMapping("getAccount")
    public String GetAccountAll() {
        System.out.println("controller....");
        List<Account> all = accountService.findAll();
        all.forEach(o-> System.out.println(o));

        return "success";
    }

    @GetMapping("getAccountById")
    public String getAccountById(int id){
        Account oneById = accountService.findOneById(id);
        System.out.println(oneById);

        return "success";
    }

    @PostMapping("update")
    public String updateAccount(Account one) {
        boolean b = accountService.updateACCount(one);
        System.out.println(b);
        return "success";
    }

    @GetMapping("delete")
    public String deleteAccount(int id) {
        boolean b = accountService.deleteAccount(id);
        System.out.println(b);
        return "success";
    }

    @PostMapping("insert")
    public String insertAccount(Account one){
        boolean b = accountService.insertAccount(one);
        System.out.println(b);
        return "success";
    }
}
